from flask import request

import json

def get_data():
    data=request.data
    if data:
        data=json.loads(data)
    else:
        data=request.form
    return data

def return_json(code,msg):
    dict1={"code":code,"msg":msg}
    ret=json.dumps(dict1,ensure_ascii=False)
    return ret


# 导入七牛云
from qiniu import Auth

def getQNToken():
    # 需要填写你的 Access Key 和 Secret Key
    access_key = '4DWkOsYP4ZcDaA64Oq26ywJWbMEEtQHQB_JACfLT'
    secret_key = '-kbUmmaTekFta_vQzsd6teMmSIfvicRt2P9cPfcs'
    # 实例化 传入access_key和secret_key
    q = Auth(access_key, secret_key)
    # 指定空间名
    bucket_name = 'fla'
    # 生成上传 Token
    token = q.upload_token(bucket_name)
    return token



#容联云发短信接口
# #手机短信
from ronglian_sms_sdk import SmsSDK
accId = '8aaf07087bc82708017bf7aae5000e27'   #8aaf07087bc82708017bf7aae5000e27
accToken = 'f53d9d4740ed40adb6829538dc940709' #f53d9d4740ed40adb6829538dc940709
appId = '8aaf07087bc82708017bf7aae5e00e2e'  #8aaf07087bc82708017bf7aae5e00e2e
import json

ADDRESS_MAX_COUNT=10

def send_message(mobile,code,time):
    sdk = SmsSDK(accId, accToken, appId)
    tid = '1'
    mobile = mobile
    datas = (code, time)
    resp = sdk.sendMessage(tid, mobile, datas)
    result = json.loads(resp)
    if result['statusCode'] == '000000':
        return 1
    return 2